﻿Public Class DGvTrx
    Inherits System.Windows.Forms.DataGridView
    'this function do the half of job 
    'when you hit a key (like return) it transforms like you 
    'have been hit the tab key
    'this doent work when you are editing the cell

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

        If keyData = Keys.Return Then
            keyData = Keys.Tab
            With msg
                .WParam = Keys.Tab
            End With
        End If

        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

    'this second function works when you are editing the cell
    'does the same as the function above changing return for tab
    Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean

        If keyData = Keys.Return Then
            keyData = Keys.Tab
        End If

        Return MyBase.ProcessDialogKey(keyData)
    End Function
End Class
